home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-2.iso / Files II / Prog / M / MacOberon 4.0.sit / MacOberon 4.0 / Toolbox Interfaces / Import.Mod (.txt) < prev    next >
Encoding:
Oberon Text  |  1993-10-25  |  2.1 KB  |  57 lines  |  [.Ob./.Ob5]

  1. Syntax10.Scn.Fnt
  2. ParcElems
  3. Alloc
  4. Syntax10i.Scn.Fnt
  5. MODULE Import;  (*od/mf 25.10.93*)
  6. (* This is a sample module that shows how to combine Macintosh and Oberon code. Execution of the command Import.Text will open a file selector box. If you select a text file, it will be opened in a new TextViewer.
  7.     Compile the toolbox files if necessary:
  8.         Compiler.Compile
  9.             MacMemory.Mod/s    MacImaging.Mod/s
  10.             MacToolbox.Mod/s    MacFiles.Mod/s
  11.             MacProcesses.Mod/s    MacOSUtils.Mod/s
  12.             MacMoreToolbox.Mod/s    MacText.Mod/s
  13.             MacIAC.Mod/s    ~
  14.     Then, compile this module:
  15.         Compiler.Compile Import.Mod ~
  16.     Now, execute the new command:
  17.         Import.Text
  18. The corresponding export procedure is left as an exercise to the reader. *)
  19.     IMPORT
  20.         SYSTEM, Oberon, MenuViewers, Texts, TextFrames,
  21.         ME:=MacMemory, MF:=MacFiles, TB:=MacToolbox;
  22.     CONST
  23.         Menu="System.Close  System.Copy  System.Grow  Edit.Store";
  24.         W: Texts.Writer;
  25.     PROCEDURE Text*;
  26.         VAR
  27.         (* Oberon Vars *)
  28.             V: MenuViewers.Viewer; T: Texts.Text;
  29.             ch: CHAR;
  30.             x, y: INTEGER; name: ARRAY 32 OF CHAR;
  31.         (* Macintosh Vars *)
  32.             buf: ME.Ptr; myTypes: MF.SFTypeList;
  33.             myReply: MF.StandardFileReply;
  34.             inFile: INTEGER; err: INTEGER; count, read: LONGINT;
  35.     BEGIN
  36.         myTypes[0]:=054455854H;    (* TEXT *)
  37.         MF.StandardGetFile(NIL, 1, myTypes, myReply);
  38.         IF    myReply.sfGood    THEN
  39.             err:=MF.FSpOpenDF(myReply.sfFile, 0, inFile);
  40.             err:=MF.GetEOF(inFile, count);
  41.             err:=MF.SetFPos(inFile, 1, 0);
  42.             buf:=SYSTEM.VAL(ME.Ptr, SYSTEM.ADR(ch));
  43.             WHILE    count>0    DO
  44.                 read:=1;
  45.                 err:=MF.FSRead(inFile, read, buf);
  46.                 Texts.Write(W, ch); DEC(count)
  47.             END;
  48.             err:=MF.FSClose(inFile);
  49.             TB.GetStr255(SYSTEM.VAL(ME.Str255, myReply.sfFile.name), name);
  50.             T:=TextFrames.Text(""); Oberon.AllocateUserViewer(Oberon.Mouse.X, x, y);
  51.             V:=MenuViewers.New(TextFrames.NewMenu(name, Menu), TextFrames.NewText(T, 0), TextFrames.menuH, x, y);
  52.             Texts.Append(T, W.buf)
  53.         END
  54.     END Text;
  55. BEGIN    Texts.OpenWriter(W)
  56. END Import.
  57.